import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_demo3/util/dio_util.dart';
import 'package:flutter_swiper/flutter_swiper.dart';



class NewsSwiper extends StatefulWidget {
  @override
  _NewsSwiperState createState() => _NewsSwiperState();
}

class _NewsSwiperState extends State<NewsSwiper> {
  List<String> _imgSrcList;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 300,
      height: 200,
      child: Swiper(
        loop: true,
        autoplay: true,
        autoplayDelay: 5000,
        autoplayDisableOnInteraction: true,
        itemCount: _imgSrcList.length,
        itemBuilder: (BuildContext context, int index) {
          return Image.network(
            _imgSrcList[index], fit: BoxFit.cover);
        },
      ),
    );
  }


  @override
  void initState() {
    int maxSize = 4;
    _imgSrcList = new List();
    Random random = new Random();
    for (int i = 1; i < maxSize + 1; i++) {
      _imgSrcList.add(DioUtil.head_url + "news/swiper/" +
          (random.nextInt(3) + 1).toString() + ".jpg");
    }
    //print("----------"+_imgSrcList.toString());
  }
}





